package cn.jly.spring.ioc.beans;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author lanyangji
 * @description student类
 * @date 2020/11/8 下午 12:44
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Student implements BeanPostProcessor {
    private Long id;
    private String name;
    private String address;
    private String nickname;
    private Book book;
    /**
     * 简单集合部分
     */
    private String[] hobbies;
    private List<String> list;
    private Set<String> sets;
    private Map<String, String> map;

    /**
     * 对象集合
     */
    private List<Order> orders;

    /**
     * 使用xml中的公共集合
     */
    private List<String> books;

    /**
     * 初始化方法
     */
    public void initMethod() {
        System.out.println("调用初始化方法");
    }

    /**
     * 销毁方法
     */
    public void destroyMethod() {
        System.out.println("调用销毁方法");
    }

    /**
     * 初始化之前调用
     *
     * @param bean
     * @param beanName
     * @return
     * @throws BeansException
     */
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("Student.postProcessBeforeInitialization");
        return bean;
    }

    /**
     * 初始化之后调用
     *
     * @param bean
     * @param beanName
     * @return
     * @throws BeansException
     */
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("Student.postProcessAfterInitialization");
        return bean;
    }
}
